How to
... enable customize button
Select a toolbar in designer and set HasCustomizeButton property to true.
... change order of toolbar buttons
Select ItemCollection property and open ToolbarButton Collection Editor. Using this editor you can change order of items in collection.
... change order of popup menu items
Select parent menu button, select property PopupMenuButtons and open ToolbarMenuButton Collection Editor.
Note. You can make the above actions in the second way using Command Editor.
... make a toolbar to take the full dock row
Set toolbar's ExclusiveRow property to true.
... disable full and alternative toolbar or menu customization
Set IsCustomizable property to false.
... put a toolbar on docking pane or any other control
Select toolbar, set IsStandAloneMode property to true. The toolbar will be taken out of docking and attached to the top of client area. You can drag and drop this toolbar anywhere. DockingPane has a special property BCGToolbar which allows quickly attach a toolbar to docking pane.
... tell a toolbar to ignore the current visual theme and use OfficeXP theme (usable for dialogs)
Select toolbar, set IsDialogControl property to true.
... disable tool tips
Select toolbar, set ShowTooltips property to false.
... know when a toolbar button was clicked
Handle ToolbarButtonClick event. This is useful when you need to know that a button residing on a particular toolbar was clicked (in opposite to ExecuteCommand).
... modify a popup menu at runtime depending on the current context
Handle CommandBarManager.OnBeforeShowPopupMenu event. ShowPopupMenuEventArgs contains a reference to popup menu bar being shown (PopupBar) and a reference to parent menu button (ParentMenuButton). If parent menu button is null, then the popup menu is displayed as a context menu by right click on a docking pane or MDIConatiner. PopupMenuBar.Context property helps to determine the context of the popup menu being displayed. Otherwise you can examine the parent menu button (and see its ID).
When you've decided how to modify the popup menu being shown, just create a new button and insert it using PopupMenuBar.InsetButton (int insertAt, ToolbarButton button).
If you wish to prevent the popup menu from being shown, set ShowPopupMenuEventArgs.Cancel property to true.
... display a popup menu with the full list of toolbars (As View | Toolbars in Visual Studio development environment)
In designer add View | Toolbars button. Create a popup menu for Toolbars button with a single item named "Toolbar List". Set IsItemList property to true.
Remember ID of "Toolbars" button (139, for example).
Subscribe to CommandBarManager.OnBeforeShowPopupMenu event.
OnBeforeShowPopupMenu handler Copy Code
void OnBeforeShowPopupMenu(object sender, ShowPopupMenuEventArgs e) { PopupMenuBar popup = e.PopupBar; if (e.ParentButton.ID == 139) { if (Toolbar.IsCustomizeMode()) { e.Cancel = true; return; } m_commandBarManagerMain.BuildCommandBarMenu(popup); } }
In the above code we check for the parent menu button, don't allow the menu to be shown in customize mode and call CommandBarManager.BuildCommandBarMenu. It removes all items from the popup, loops over list of command bars and adds only dockable command bars and "Customize..." button. It has one overload which allows greater control over this popup menu:
... add a toolbar button at runtime
BuildCommandBarMenu overload Copy Code
void BuildCommandBarMenu(PopupMenuBar popup, bool addCustomizeButton, bool clearCollection, bool internalProcessing);
Instantiate a button, set its properties and call Toolbar.ItemCollection.Add. This should be done before LoadState.
Copy Code